<template>
  <div class="twoxm-cart-item">
     <van-checkbox :value="check" @click="toggleItemCheck({ id })" shape="square" checked-color="#26a2ff"></van-checkbox>
    <img class="twoxm-cart-item-img" :src="img" alt="">
    <div class="twoxm-cart-item-main">
      <h4>{{ title }}</h4>
      <div class="twoxm-cart-item-main-price">
        <span>￥{{ price | toFix2 }}</span>
        <van-stepper
          :value="count"
          @plus="plusItemCount({ id })"
          @minus="minusItemCount({ id })"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { createNamespacedHelpers } from 'vuex'
const cart = createNamespacedHelpers('cart')

export default {
  name: 'mycartitem',
  props: ['id', 'title', 'img', 'price', 'count', 'check'],
  methods: {
    ...cart.mapMutations([
      'toggleItemCheck',
      'plusItemCount',
      'minusItemCount'
    ])
  }
}
</script>

<style lang="scss" scoped>
.twoxm-cart-item {
  display: flex;
  padding: 10px;
  &-img {
    margin: 0 5px;
    width: 80px;
  }
  &-main {
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: space-between;
    h4 {
      line-height: 2;
      font-size: 14px;
      color: #333;
    }
    &-price {
      display: flex;
      justify-content: space-between;
      > span {
        color:#fa585a;
      }
    }
  }
}
</style>
